﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TV4Home.WebInterface.UI
{
    public partial class MediaStreamingWindow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
                ViewState.Clear();

            if (Request.QueryString["channelId"] != null)
                this.CurrentChannelID = Convert.ToInt32(Request.QueryString["channelId"]);

            ScriptManager.RegisterStartupScript(this, typeof(Page), "flowplayer", "flowplayer('tvPlayer', 'MediaStreaming/flowplayer/flowplayer-3.1.5.swf', { clip: { url: '" + GetMediaSourceURL() + "', autoPlay: true, autoBuffering: true, bufferLength: 5, live: true, scaling: 'fit', seekableOnBegin: false } });", true);
        }

        protected string GetMediaSourceURL()
        {
            if (this.CurrentChannelID == 0)
                return "";
            else
                return "MediaStreaming/GetLiveTVStream.ashx?id=" + this.CurrentChannelID;
        }

        #region ViewState Properties
        private int CurrentChannelID
        {
            get
            {
                if (ViewState["currentChannelID"] == null)
                    ViewState["currentChannelID"] = 0;

                return (int)ViewState["currentChannelID"];
            }
            set
            {
                ViewState["currentChannelID"] = value;
            }
        }
        #endregion
    }
}
